package homework.test;

import homework.bean.Teacher;
import homework.mapper.TeacherMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class work1 {
    @Test
    public void selectAll() throws IOException {
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");

        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);

        SqlSession sqlSession = build.openSession(true);

        TeacherMapper mapper = sqlSession.getMapper(TeacherMapper.class);

        List<Teacher> teachers = mapper.selectAll();

        for (Teacher teacher : teachers) {
            System.out.println(teacher.getId()+":"+teacher.getName());
        }
        sqlSession.close();
        is.close();
    }
}
